﻿namespace Hotel.Web.Helpers
{
    using System;
    using Hotel.Model.Infrastructure;
    using System.Threading;
    using System.Globalization;

    /// <summary>
    /// Provides auxiliary functionality for operations with session
    /// </summary>
    public static class ApplicationStateHelper
    {
        /// <summary>
        /// Culture value cookie name.
        /// </summary>
        public const string CULTURE = "culture";


        #region Public Properties

        public static Lcid Culture
        {
            get
            {
                Lcid culture;
                if (Enum.TryParse(CookieUtil.GetCookieValue(CULTURE), out culture))
                    return culture;

                return Lcid.En;
            }
            set
            {
                if (CookieUtil.CookieExists(CULTURE))
                    CookieUtil.DeleteCookie(CULTURE);

                CookieUtil.CreateCookie(CULTURE, value.ToString(), null);
            }
        }

        #endregion

        #region Public Methods

        public static void SetCulture()
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ApplicationStateHelper.Culture.ToString());
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Thread.CurrentThread.CurrentUICulture.Name);
        }

        #endregion
    }
}
